package com.laikan.reader.bookfriend.mactivity;

import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.laikan.library.components.activitys.BasicActivity;
import com.laikan.reader.R;
import com.laikan.reader.bookfriend.utils.ImageUtils;
import com.laikan.reader.bookfriend.utils.LogUtils;


/**
 * Created by admin on 2016/11/1.
 * 初始化标题的activity
 */
public abstract class BaseTitleActivity extends BasicActivity{

    protected ImageView mIvBack;
    protected TextView mTvTitle;
    protected Button mBtRight;
    protected View mRLToumig;
    protected BitmapDrawable mDrawableBack;
    protected RelativeLayout mTitleLayout;
    private RelativeLayout mBackLayout;

    @Override
    protected void assignViews() {
        setContentView(getLayoutId());
        initTitleBar();
    }

    protected abstract int getLayoutId();

    @Override
    protected abstract void initData();

    @Override
    protected abstract void setListener();

    protected void initTitleBar() {
        mIvBack = (ImageView)findViewById(R.id.title_iv_back);//返回的图片
        mTvTitle = (TextView)findViewById(R.id.title_tv_title);//标题文本
        mBtRight = (Button)findViewById(R.id.title_bt_right);//右边按钮
        mRLToumig = (View)findViewById(R.id.title_re_toumig);//标题前背景为半透明
        mTitleLayout = (RelativeLayout)findViewById(R.id.title_layout);//标题的布局
        mDrawableBack = ImageUtils.getBlueBackButton();//返回按钮蓝色
        mBackLayout = (RelativeLayout) findViewById(R.id.title_back_layout);
        setTitleBar(isTitleBarAlpha());

        mBackLayout.setOnClickListener(this);
    }


    public void setTitleBar(boolean isAlpha){
        if (isAlpha){
            mIvBack.setImageResource(R.drawable.lk_back_small);
            mTvTitle.setVisibility(View.INVISIBLE);
            mBtRight.setVisibility(View.INVISIBLE);
            mTitleLayout.getBackground().setAlpha(0);
            mRLToumig.setVisibility(View.INVISIBLE);
        }else{
            mIvBack.setImageDrawable(mDrawableBack);
            mTvTitle.setVisibility(View.VISIBLE);
            mBtRight.setVisibility(View.VISIBLE);
            mRLToumig.setVisibility(View.VISIBLE);

            mTitleLayout.getBackground().setAlpha(255);
        }
        setTitleBarStatus(isAlpha);
    }

    protected boolean isAlpha;
    protected void setTitleBarStatus(boolean isAlpha){
        this.isAlpha = isAlpha;
    }

    protected boolean getTitleBarStatus(){
        return isAlpha;
    }

    @Override
    protected void onClickEvent(View view) {
        if (view.getId() == R.id.title_back_layout){
            LogUtils.log("back layout onclick");
            finish();
        }
    }

    protected boolean isTitleBarAlpha() {
        return false;
    }

}
